import { CONST } from "../common/global";
import axios from "axios";

// 添加响应拦截器
axios.interceptors.response.use(
  function (response: any) {
    // 2xx 范围内的状态码都会触发该函数。
    return response;
  },
  function (error: any) {
    // 超出 2xx 范围的状态码都会触发该函数。
    if (error.response.status === 401 && error.response.data.code === "9000")
      window.location.replace(error.response.data.message);
    return Promise.reject(error);
  }
);

const BASE = {
  LOGIN: function (param: any) {
    return axios.post(CONST.BASE_URL + "/login", param);
  },

  INFO: function (param: any) {
    return axios.get(CONST.BASE_URL + "/user/info", { params: param });
  },

  GET_GRID_LIST: function (param: any) {
    return axios.get(CONST.BASE_URL + "/baseInfo/selectGridList", { params: param });
  },
};

const BOND = {
  LIST: function (param: any) {
    return axios.get(CONST.BASE_URL + "/bond/list", { params: param });
  },
  USE: function (param: any) {
    return axios.post(CONST.BASE_URL + "/bond/use", param);
  },
  ADD: function (param: any) {
    return axios.post(CONST.BASE_URL + "/bond/add", param);
  },
  ALLOW_USE: function (param: any) {
    return axios.post(CONST.BASE_URL + "/bond/allowUse", param);
  },
};

export { BASE, BOND };
